<?php
/**
 * Created by PhpStorm.
 * User: Orange
 * Date: 2018/5/8
 * Time: 13:58
 */
namespace app\index\controller;


use app\common\controller\Frontend;
use app\common\utils\Constant;
use app\index\logic\CategoryLogic;

class Category extends Frontend
{
    /**
     * 根据父ID获取分类信息
     * @return \think\response\Json
     */
    public function ajax_get_category()
    {
        $result = $this->check();
        if (!$result['success']) {
            return $this->returnJson($result['msg'], $result['code']);
        }
        $parentId = $this->request->post('parent_id');
        $logic = new CategoryLogic();
        $result = $logic->GetAllCategory($parentId);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }

    }
    /**
     * 获取界类别
     * @return \think\response\Json
     */
    public function ajax_get_category_kingdom()
    {
        $result = $this->check();
        if (!$result['success']) {
            return $this->returnJson($result['msg'], $result['code']);
        }
        $logic = new CategoryLogic();
        $result = $logic->GetKingdomCategory();
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }

    }

}